package com.mycompany.app.hr.eleave.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * reconcile job: [process leave record]
 This is a daily background process. 
 It will generate leave payment for those leave record 
 which leave date is due according to predefined leave payment rules 
 or assigned pay factor. 
 1. Add AL, SL, SD(CS,LS) consumed fields; (refers to the leave_session)
 2. deduct applied fields for AL, SL
 3. calculate pay days   
 
 =========================>
 pay days的计算可以在leave approval后, 创建leave record的时候计算.不用放在
 每日的后台SP job里.增加了系统的复杂性

 When to use: Run once each day.
 * @author Shawn.guo
 *
 */
public class LeaveRecord {

    public static enum ProcessStatus {
        UNPROCESSED
    }

    public static enum LeaveSession {
        WHOLE_DAY, FIRST_HALF_DAY, SECOND_HALF_DAY
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "leave_record_id")
    private Long id;

    @Column(name = "gid")
    private String gid;

    @ManyToOne()
    @JoinColumn(name = "leave_type_id")
    private LeaveType leaveType;

    @Column(name = "leave_date")
    private Date leaveDate;

    @Enumerated(EnumType.STRING)
    @Column(name = "leave_session", nullable = false)
    private LeaveSession leaveSession;
    
    @Column(name = "apply_date")
    private Date applyDate;
    
    /**
     * calculate when leave record is due. In seagate, it's calculated in daily
     * back-ground job.
     * 1=full day   0.5=first half day/second half day
     */
    @Column(name = "leave_days")
    private Float leaveDays;

    // support dynamic pay ratio like SP leave in seagate
    @Column(name = "pay_ratio")
    private Float payRatio;

    /**
     * for payroll calculation.
     * pay_days=pay_ratio*leave_days
     */
    @Column(name = "pay_days")
    private Float payDays;

    @Enumerated(EnumType.STRING)
    @Column(name = "process_status", nullable = false)
    private ProcessStatus processStatus;
    
    
    @Column(name = "remark")
    private String remark;

    // =======================================================
    @Override
    public String toString() {

        return ToStringBuilder.reflectionToString(this);
    }

    // =======================================================

    public Long getId() {

        return id;
    }

    public void setId(Long id) {

        this.id = id;
    }

    public Float getPayRatio() {

        return payRatio;
    }

    public void setPayRatio(Float payRatio) {

        this.payRatio = payRatio;
    }

    public String getGid() {
    
        return gid;
    }

    public void setGid(String gid) {
    
        this.gid = gid;
    }

    public LeaveType getLeaveType() {
    
        return leaveType;
    }

    public void setLeaveType(LeaveType leaveType) {
    
        this.leaveType = leaveType;
    }

    public Date getLeaveDate() {
    
        return leaveDate;
    }

    public void setLeaveDate(Date leaveDate) {
    
        this.leaveDate = leaveDate;
    }

    public LeaveSession getLeaveSession() {
    
        return leaveSession;
    }

    public void setLeaveSession(LeaveSession leaveSession) {
    
        this.leaveSession = leaveSession;
    }

    public Date getApplyDate() {
    
        return applyDate;
    }

    public void setApplyDate(Date applyDate) {
    
        this.applyDate = applyDate;
    }

    public Float getLeaveDays() {
    
        return leaveDays;
    }

    public void setLeaveDays(Float leaveDays) {
    
        this.leaveDays = leaveDays;
    }

    public Float getPayDays() {
    
        return payDays;
    }

    public void setPayDays(Float payDays) {
    
        this.payDays = payDays;
    }

    public ProcessStatus getProcessStatus() {
    
        return processStatus;
    }

    public void setProcessStatus(ProcessStatus processStatus) {
    
        this.processStatus = processStatus;
    }

    public String getRemark() {
    
        return remark;
    }

    public void setRemark(String remark) {
    
        this.remark = remark;
    }
    
}
